Add LambdaInitialData<T> + AddInitialData lambda overload (8.14.0)#250
Merged
jeremydmiller merged 1 commit intomasterfrom Apr 20, 2026
Merged
Add LambdaInitialData<T> + AddInitialData lambda overload (8.14.0)#250jeremydmiller merged 1 commit intomasterfrom
jeremydmiller merged 1 commit intomasterfrom
Conversation
Lets callers register small inline seeders without authoring a dedicated
IInitialData<TContext> class:
services.AddInitialData<ShopDbContext>(async (ctx, ct) =>
{
ctx.Customers.Add(new ShopCustomer { Name = "Inline" });
await ctx.SaveChangesAsync(ct);
});
Registered as a singleton LambdaInitialData<T> so it coexists with the
existing class-based AddInitialData<TContext, TData>() form and runs in
registration order via the DatabaseCleaner<T>.ResetAllDataAsync path.
Also adds a [Collection("FkDependencyDbContext")] guard to
database_cleaner_tests so it serializes with the new
lambda_initial_data_tests (both share the fk_dep_test schema).
Bumps Directory.Build.props Version to 8.14.0 for the Wolverine consumer
that depends on this work (JasperFx/wolverine#2539).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
3 tasks
erikshafer
pushed a commit
to erikshafer/wolverine
that referenced
this pull request
Apr 20, 2026
Makes the EF Core dev-loop faster and more discoverable:
- Auto-register Weasel's DatabaseCleaner<> (open generic) inside
UseEntityFrameworkCoreTransactions(). Callers no longer need a
per-context services.AddDatabaseCleaner<T>() — resolving
IDatabaseCleaner<T> / DatabaseCleaner<T> just works.
- New IHost.ResetAllDataAsync<T>() extension for finer-grained
per-DbContext test teardown. Creates its own scope, resolves the
DbContext first, then the cleaner, then runs delete+reseed.
- New documentation:
* docs/guide/durability/efcore/index.md — Development-time usage
section covering Weasel migrations vs EF Core migrations,
IInitialData mention, and reset guidance.
* docs/guide/durability/efcore/initial-data.md — IInitialData<T>
patterns: class-based vs lambda, layered seeders, idempotency,
when not to use.
* docs/guide/durability/efcore/batch-queries.md — four handler
patterns for the Wolverine batching story, with locally measured
perf numbers (2.78x speedup, 4-query handler) and links out to
Weasel's fluent BatchedQuery reference.
- Weasel link sweep: replaced github.com links with
https://weasel.jasperfx.net/... where applicable.
- ItemService sample: SeedSampleItems IInitialData<ItemsDbContext>
registered via AddInitialData<TContext, TData>(), with a comment
showing the Weasel 8.14 lambda overload.
- Bumps Weasel.* package references to 8.14.0 to pick up the new
LambdaInitialData<T> + AddInitialData lambda overload
(JasperFx/weasel#250).
Tests: 7/7 pass for the cleaner-related suite
(auto_database_cleaner_registration_tests + database_cleaner_usage_tests).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Lets callers register small inline seeders without authoring a dedicated
IInitialData<TContext>class:Registered as a singleton
LambdaInitialData<T>so it coexists with the existing class-basedAddInitialData<TContext, TData>()form and runs in registration order viaDatabaseCleaner<T>.ResetAllDataAsync.Background
Needed by Wolverine GH-2539 — part of the "EF Core dev-time improvements" bullet list. Wolverine will consume the new API in its dev-time documentation and reset-between-tests story. Package bumped to 8.14.0 so Wolverine can pull the new version.
Changes
src/Weasel.EntityFrameworkCore/LambdaInitialData.csIInitialData<TContext>implementation wrapping aFunc<TContext, CancellationToken, Task>src/Weasel.EntityFrameworkCore/DatabaseCleanerExtensions.csAddInitialData<TContext>(Func<TContext, CancellationToken, Task>)overload registered as singletonsrc/Weasel.EntityFrameworkCore.Tests/Postgresql/lambda_initial_data_tests.cssrc/Weasel.EntityFrameworkCore.Tests/Postgresql/database_cleaner_tests.cs[Collection("FkDependencyDbContext")]so it serializes with the new suite (both share thefk_dep_testschema)src/DocSamples/DatabaseCleanerSamples.cssample_efcore_lambda_initial_dataregiondocs/efcore/database-cleaner.mdIInitialDataDirectory.Build.propsTest plan
dotnet test --framework net9.0 --filter "FullyQualifiedName~lambda_initial_data|FullyQualifiedName~database_cleaner"— 7/7 pass (3 new + 4 existing cleaner tests)dotnet build— 0 errors🤖 Generated with Claude Code